//
//  ZDProductCell.m
//  1012GiftTips
//
//  Created by Apple on 15/10/15.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDProductCell.h"
#import "ZDShowImage.h"

@interface ZDProductCell ()

@property (weak, nonatomic) IBOutlet UIImageView *productImage;

@property (weak, nonatomic) IBOutlet UIButton *favoriteBtn;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;


@end

@implementation ZDProductCell

- (void)awakeFromNib
{
    self.productImage.layer.cornerRadius = 5;
    
    self.productImage.layer.masksToBounds = YES;
    
    self.favoriteBtn.layer.cornerRadius = 15;
    
    self.favoriteBtn.layer.masksToBounds = YES;
}


+ (instancetype)productCell:(UITableView *)tableView
{
    static NSString *ID = @"ZDProductCell";
    
    ZDProductCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZDProductCell class]) owner:nil options:nil] lastObject];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}


- (void)setShowImage:(ZDShowImage *)showImage
{
    _showImage = showImage;
    
    self.productImage.image = [UIImage imageNamed:showImage.image];
}


//按钮点击事件  松开后调用
- (IBAction)favoriteBtnClick:(UIButton *)sender
{
    self.favoriteBtn.selected = !self.favoriteBtn.selected;
    
    NSInteger favoriteNum = self.favoriteBtn.currentTitle.intValue;
    
    favoriteNum = self.favoriteBtn.selected ? favoriteNum+1 : favoriteNum-1;
    
    [self.favoriteBtn setTitle:[NSString stringWithFormat:@"%ld", favoriteNum] forState:UIControlStateNormal];
}

@end
